package com.heima.admin.job;

import com.aliyuncs.ram.model.v20150501.CreateUserRequest;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.common.exception.CustomException;
import com.heima.feigns.wemedia.WemediaFeign;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *执行任务
 */
@Component
@Slf4j
public class WeMediaNewsAutoScanJob {

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @Autowired
    WemediaFeign wemediaFeign;

    @XxlJob("wemediaAutoScanJob")
    public ReturnT<String> autoScanJob(String param){
        log.info("自媒体文章审核调度任务开始执行....");
        // 调用审核方法
        // 先获取文章id
        List<Integer> release = wemediaFeign.findRelease();
        if (release == null){
            throw new CustomException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        // 遍历集合查出id
        for (Integer id : release) {
            wemediaNewsAutoScanService.autoScanByMediaNewsId(id);
        }

        log.info("自媒体文章审核调度任务执行结束....");
        return ReturnT.SUCCESS;
    }
}
